package com.ywb.controller;



import com.ywb.anno.Log;
import com.ywb.pojo.PageResult;
import com.ywb.pojo.Result;
import com.ywb.pojo.TradeRecord;
import com.ywb.pojo.TradeRecordQueryParam;
import com.ywb.service.TradeRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/tradeRecords")
@RestController
public class TradeRecordController {

    @Autowired
    private TradeRecordService tradeRecordService;

//    @GetMapping
//    public Result list() {
//        log.info("查询全部交易记录");
//        List<TradeRecord> records = tradeRecordService.findAll();
//        return Result.success(records);
//    }
    @GetMapping
    public Result page(TradeRecordQueryParam tradeRecordQueryParam)
    {
        log.info("分页查询，参数{}", tradeRecordQueryParam);
        PageResult<TradeRecord> pageResult = tradeRecordService.page(tradeRecordQueryParam);
        return Result.success(pageResult);
    }


//    @Log
//    @DeleteMapping
//    public Result deleteById(@RequestParam("id") Long tradeId) {
//        log.info("删除交易记录{}", tradeId);
//        tradeRecordService.deleteById(tradeId);
//        return Result.success();
//    }

    @Log
    @PostMapping
    public Result add(@RequestBody TradeRecord tradeRecord) {
        log.info("新增交易记录{}", tradeRecord);
        tradeRecordService.add(tradeRecord);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getinfo(@PathVariable("id") Long tradeId) {
        log.info("根据ID查询交易记录{}", tradeId);
        TradeRecord record = tradeRecordService.getById(tradeId);
        return Result.success(record);
    }

    @Log
    @PutMapping
    public Result update(@RequestBody TradeRecord tradeRecord) {
        log.info("修改交易记录{}", tradeRecord);
        tradeRecordService.update(tradeRecord);
        return Result.success();
    }


    @DeleteMapping
    public Result delete(@RequestParam List<Integer>ids){
        log.info("删除交易记录,id:{}",ids);
        tradeRecordService.delete(ids);
        return Result.success();
    }
}